<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function randomPro() {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            const num = parseInt(Math.random() * 100)
            if (num > 0 && num < 50) {
              resolve('我成功了' + num)
            } else {
              reject('我失败了' + num)
            }
          }, 1000)
        })
      }

      //   randomPro().then().catch()
      randomPro().then(
        (res) => {
          console.log('res', res)
        },
        (err) => {
          console.log('err', err)
        }
      )
      // .catch((err) => {
      //   console.log('err', err)
      // })
    </script>
  </body>
</html>
